﻿using Cdx.Common.Contracts;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cdx.Common
{
    public class ServicesFactory
    {
        public static NameValueCollection AppSettings = ConfigurationManager.AppSettings;

        public static IAuthentication AuthenticationService
        {
            get { return CreateService<IAuthentication>("AuthenticationService"); }
        }

        public static IClassification ClassificationService
        {
            get 
            {
                throw new NotImplementedException();
            }
        }

        public static IRecognition RecognitionService
        {
            get
            {
                throw new NotImplementedException();
            }
        }

        public static IDocumentManager DocumentManagerService
        {
            get{ return CreateService<IDocumentManager>("DocumentManagerService"); }
        }

        public static IEngine EngineService
        {
            get { throw new NotImplementedException(); }
        }


        private static T CreateService<T>(string name)
        {
            var names = AppSettings[name].Split(new char[] { ',' });

            return (T)Activator.CreateInstance(names[0], names[1]).Unwrap();    
        }
    }
}
